package com.yuanchu.order.controller;

import com.yuanchu.common.utils.R;
import com.yuanchu.order.dto.SubmitOrderParamsDto;
import com.yuanchu.order.service.CheckoutOrderService;
import com.yuanchu.order.utils.SecurityUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-05 14:05
 */
@RestController
@RequestMapping("checkout")
public class CheckoutController {

    @Resource
    private CheckoutOrderService checkoutOrderService;



    @ApiOperation(value = "/api/checkout/order", tags = "获取订单结算数据")
    @GetMapping("/order")
    public R processCheckoutOrder(@RequestParam Map<String, Object> params) {
        Integer userId = SecurityUtil.getUserId();

        Map<String, Object> checkoutOrder = checkoutOrderService.checkoutOrder(params, userId);

        return R.ok().put("data", checkoutOrder);
    }

    @ApiOperation(value = "/api/checkout/order/submit", tags = "获取订单结算数据")
    @PostMapping("/submit")
    public R checkoutOrderSubmit(@RequestBody SubmitOrderParamsDto params) {
        Integer userId = SecurityUtil.getUserId();
        Map<String, Object> checkoutOrder = checkoutOrderService.checkoutOrderSubmit(params, userId);

        return R.ok().put("data", checkoutOrder);
    }


}
